const mongoose  = require('mongoose')

const errorMsg = () => {
    console.log('连接失败')
}

module.exports = (success, errorFn = errorMsg) => {
    mongoose.connect('mongodb://127.0.0.1:27017/test')

    mongoose.connection.once('open', () => {
        console.log('连接成功')
        success()
    })

    mongoose.connection.on('error', () => {
        errorFn()
    })
}